//手动创建axios实例
import axios from "axios"
const service=axios.create({
  baseURL:'/api',
  timeout:5000
});

// const instance = axios.create({
//   baseURL: 'http://localhost:8088/dev', // 后端服务地址
//   timeout: 5000,
// });

// export const getOrders = () => {
//   return instance.get('/orders');
// };
import { useLoginStore } from "@/stores/LoginStore";
service.interceptors.request.use(
  config => {
    console.log('request拦截器...')
    let loginStore = useLoginStore()
    if(loginStore.loginToken){
        config.headers['Authorization'] = `${loginStore.loginToken}`
    }
    return config;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
)
service.interceptors.response.use(
  response => {
    console.log('response拦截器...')
    return response;
  },
  error => {
    console.log('err' + error);
    return Promise.reject(error);
  }
);

export default service;